package com.wnhz.work.yz.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.MyApplication;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.base.BaseLGAdapter;
import com.wnhz.work.yz.base.BaseViewHolder;
import com.wnhz.work.yz.bean.AddressBean;
import com.wnhz.work.yz.bean.FitmentBean;
import com.wnhz.work.yz.utils.SystemUtils;
import com.wnhz.work.yz.utils.Url;
import com.wnhz.work.yz.utils.xutils3.MyCallBack;
import com.wnhz.work.yz.utils.xutils3.XUtil;
import com.wnhz.work.yz.view.SwitchView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.x;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * ---结算
 */
public class SettleAccountsActivity extends BaseActivity implements View.OnClickListener, SwitchView.OnStateChangedListener {
    private static final int VALUE_TAX = 895;
    private BaseLGAdapter<FitmentBean> adapter;
    private List<FitmentBean> list = new ArrayList<>();
    private ListView listView;

    private SwitchView switchButton;

    private View include_address, include_noAddress;
    private TextView tv_name, tv_phone, tv_address;
    private View rl_invoice;
    private TextView invoice_tv;
    private TextView pay_type_message;

    private static final int CODE_ADDRESS = 111;
    private static final int CODE_INVOICE = 112;

    private double weight;
    private TextView freight_tv;

    private String addrId = "";
    private String receiptAddrId = "";
    private String invoiceType = "";
    private String invoiceTitle = "";
    private String company = "";
    private String receiptType = "";
    private String type = "";

    private TextView all_money;
    private TextView pay_money;

    private String allPrice;
    private int textColorLi, textColorNor;
    private int BackColorLi, BackColorNor;
    private TextView pay_type1, pay_type2, pay_type3;
    private EditText edit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settle_accounts);
        initData();
        initTitle();

        switchButton = (SwitchView) findViewById(R.id.switchButton);


        listView = (ListView) findViewById(R.id.listView);

        upOrder();
        adapter = new BaseLGAdapter<FitmentBean>(this, list) {
            @Override
            protected int getLayoutId() {
                return R.layout.item_start_order_shopping;
            }

            @Override
            protected void onBind(BaseViewHolder holder, int position) {
                FitmentBean bean = beanList.get(position);
                ImageView shopping_img = holder.getView(R.id.shopping_img);
                x.image().bind(shopping_img, bean.getLogo_pic());
                holder.setTextView(R.id.title_tv, bean.getGoods_name());
                holder.setTextView(R.id.material, bean.getSku_des());
                DecimalFormat df = new DecimalFormat("######0.00");
                holder.setTextView(R.id.tv_price, "¥ " + bean.getOprice());
                holder.setTextView(R.id.number_tv, "x" + bean.getNum());
            }
        };
        listView.setAdapter(adapter);

        switchButton.setOpened(false);
        switchButton.setOnStateChangedListener(this);

        /**
         * 判断是否有地址选择显示隐藏的布局
         */
        include_address = findViewById(R.id.include_choose_address);//有地址
        include_noAddress = findViewById(R.id.include_choose_noAddress);//无收货地址

        include_address.setOnClickListener(this);
        include_noAddress.setOnClickListener(this);

        include_address.setVisibility(View.GONE);// TODO  暂时设为不可见

        tv_name = (TextView) findViewById(R.id.tv_name);
        tv_phone = (TextView) findViewById(R.id.tv_phone);
        tv_address = (TextView) findViewById(R.id.tv_address);

        all_money = (TextView) findViewById(R.id.all_money);
        pay_money = (TextView) findViewById(R.id.pay_money);

        //显示隐藏发票
        invoice_tv = (TextView) findViewById(R.id.invoice_tv);

        rl_invoice = findViewById(R.id.rl_invoice);
        rl_invoice.setOnClickListener(this);

        showOrHideInvoiceLayout(false);

        freight_tv = (TextView) findViewById(R.id.freight_tv);
        pay_type_message = (TextView) findViewById(R.id.pay_type_message);
        all_money.setText("¥" + allPrice);
        pay_money.setText("" + allPrice);

        pay_type1 = (TextView) findViewById(R.id.pay_type1);
        pay_type2 = (TextView) findViewById(R.id.pay_type2);
        pay_type3 = (TextView) findViewById(R.id.pay_type3);
        pay_type1.setOnClickListener(this);
        pay_type2.setOnClickListener(this);
        pay_type3.setOnClickListener(this);
        pay_type1.setBackgroundResource(BackColorLi);
        pay_type1.setTextColor(textColorLi);
        pay_type_message.setText("注：线上支付是购买总费用加物流(配送)费用");
        edit = (EditText) findViewById(R.id.edit);

    }

    private List<FitmentBean> beanList;
    private int payType = 0;

    private void initData() {
        textColorLi = getResources().getColor(R.color.main_color);
        textColorNor = getResources().getColor(R.color.text);
        BackColorLi = R.drawable.button_bg_pick;
        BackColorNor = R.drawable.btn_white;
        weight = getIntent().getDoubleExtra("weight", 0.0);
        beanList = (List<FitmentBean>) getIntent().getSerializableExtra("bean");
        allPrice = getIntent().getStringExtra("allPrice");

    }

    private void showOrHideInvoiceLayout(boolean isInvoiceChoose) {

        if (isInvoiceChoose) {
            rl_invoice.setVisibility(View.VISIBLE);
        } else {
            rl_invoice.setVisibility(View.GONE);
        }
    }


    private TextView title;

    private void initTitle() {
        title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("结算");
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        findViewById(R.id.tv_true).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
            case R.id.pay_type1:
                pay_type1.setTextColor(textColorLi);
                pay_type2.setTextColor(textColorNor);
                pay_type3.setTextColor(textColorNor);
                pay_type1.setBackgroundResource(BackColorLi);
                pay_type2.setBackgroundResource(BackColorNor);
                pay_type3.setBackgroundResource(BackColorNor);
                payType = 0;
                pay_type_message.setText("注：线上支付是购买总费用加物流(配送)费用");
                freight_tv.setText("¥" + moneyInfo);
                double allMoney = Double.parseDouble(allPrice) + moneyInfo;
                pay_money.setText("" + allMoney);

                break;
            case R.id.pay_type2:
                pay_type1.setTextColor(textColorNor);
                pay_type2.setTextColor(textColorLi);
                pay_type3.setTextColor(textColorNor);
                pay_type1.setBackgroundResource(BackColorNor);
                pay_type2.setBackgroundResource(BackColorLi);
                pay_type3.setBackgroundResource(BackColorNor);
                payType = 1;
                pay_type_message.setText("注：只需支付商品总费用，快递费到付");
                freight_tv.setText("到付");
                pay_money.setText("" + Double.parseDouble(allPrice));
                break;
            case R.id.pay_type3:
                pay_type1.setTextColor(textColorNor);
                pay_type2.setTextColor(textColorNor);
                pay_type3.setTextColor(textColorLi);
                pay_type1.setBackgroundResource(BackColorNor);
                pay_type2.setBackgroundResource(BackColorNor);
                pay_type3.setBackgroundResource(BackColorLi);
                payType = 2;
                pay_type_message.setText("注：只需支付商品总费用，商品由买家自提");
                freight_tv.setText("自提");
                pay_money.setText("" + Double.parseDouble(allPrice));
                break;

            //下单
            case R.id.tv_true:
                if (0 == isOpened) {
                    Log.e("----", payType + "");
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setMessage("您未选择发票，如果确定不需要发票，后续将不会进行补发，如有问题请联系客服")
                            .setTitle("提示").setCancelable(false)
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {

                                    if ("1".equals(type)) {
                                        createOrder();
                                    } else if ("3".equals(type)) {
                                        createOrder1();
                                    } else {
                                        createOrder2();
                                    }
                                }
                            })
                            .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();

                                }
                            });
                    AlertDialog alert = builder.show();
                } else {
                    if (!invoice_tv.getText().toString().equals("")) {

                        if ("1".equals(type)) {
                            createOrder();
                        } else if ("3".equals(type)) {
                            createOrder1();
                        } else {
                            createOrder2();
                        }
                    } else
                        MyToast("请填写发票信息");

                }
                break;

            //填写发票信息
            case R.id.rl_invoice:
//                intent = new Intent(this, InvoiceActivity.class);
//                startActivityForResult(intent, CODE_INVOICE);
                intent = new Intent(this, SelectFapiaoActivity.class);
                startActivityForResult(intent, CODE_INVOICE);
                break;


            //有地址，前去修改
            case R.id.include_choose_address:
                intent = new Intent(this, ChooseAddressActivity.class);
                startActivityForResult(intent, CODE_ADDRESS);
                break;

            //无地址，添加收货地址
            case R.id.include_choose_noAddress:
                intent = new Intent(this, ChooseAddressActivity.class);
                startActivityForResult(intent, CODE_ADDRESS);
                break;
            default:
                break;
        }
    }

    private void createOrder2() {
        showDialog();
        Map<String, Object> map = new HashMap<>();
        StringBuilder builder = new StringBuilder("-");
        System.out.println("cartIds= " + beanList.size());
        for (int i = 0; i < beanList.size(); i++) {
            builder.append(beanList.get(i).getCart_id());
            builder.append("-");
        }
        map.put("other_type", payType);
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("cartIds", builder);
        map.put("addressId", addrId);
        map.put("remark", edit.getText().toString());
        map.put("if_receipt", isOpened);
        if (isOpened == 1) {
            map.put("invoiceId", invoiceId);
        }

        map.put("equipment", "android");
        map.put("version", "" + SystemUtils.getVersionName(SettleAccountsActivity.this));

        Map<String, Object> map2 = new HashMap<>();
        Set keys = map.keySet();
        if (keys != null) {
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Object key = iterator.next();
                Object value = map.get(key);
                Log.e("----" + key, "" + value + "\n");
                map2.put("" + key, value);
            }
        }

        XUtil.Post(Url.ORDER_JJMAKEORDER, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Log.i(TAG, "createOrder1: cartIds=== " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
//                    if ("-1".equals(res)) {
//                        //info = "请重新登录";
//                        MyToast("请重新登录");
//                        startActivity(new Intent(SettleAccountsActivity.this, LoginNewActivity.class));
//                        return;
//                    }
                    if ("1".equals(res)) {
                        JSONObject jsonObject1 = jsonObject.optJSONObject("info");
                        String order_no = jsonObject1.optString("order_no");
                        String msg = jsonObject1.optString("msg");
                        MyToast(msg);
                        String money = pay_money.getText().toString();
                        Intent intent = new Intent(SettleAccountsActivity.this, ChoosePayActivity.class);
                        intent.putExtra("order_no", order_no);
                        intent.putExtra("money", money);
                        startActivity(intent);
                        finish();
                    } else {
                        String info = jsonObject.optString("info");
                        MyToast(info);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                closeDialog();
                super.onError(ex, isOnCallback);
            }
        });

    }

    private String invoiceTitle1;
    private String taxpayerId;
    private String bank;
    private String bankAccount;
    private String address;
    private String phone;

    private void createOrder1() {
        showDialog();
        Map<String, Object> map = new HashMap<>();
        StringBuilder builder = new StringBuilder("-");
        System.out.println("cartIds= " + beanList.size());
        for (int i = 0; i < beanList.size(); i++) {
            builder.append(beanList.get(i).getCart_id());
            builder.append("-");
        }
        map.put("other_type", payType);
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("cartIds", builder);
        map.put("addressId", addrId);
        map.put("invoiceTitle", invoiceTitle1);
        map.put("taxpayerId", taxpayerId);
        map.put("address", address);
        map.put("phone", phone);
        map.put("bank", bank);
        map.put("remark", edit.getText().toString());
        map.put("bankAccount", bankAccount);
        map.put("invoiceType", type);
        map.put("if_receipt", isOpened);
        if (isOpened == 1) {
            map.put("invoiceId", invoiceId);
        }

        map.put("equipment", "android");
        map.put("version", "" + SystemUtils.getVersionName(SettleAccountsActivity.this));

        Map<String, Object> map2 = new HashMap<>();
        Set keys = map.keySet();
        if (keys != null) {
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Object key = iterator.next();
                Object value = map.get(key);
                Log.e("----" + key, "" + value + "\n");
                map2.put("" + key, value);
            }
        }
        XUtil.Post(Url.ORDER_JJMAKEORDER, map2, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Log.i(TAG, "createOrder1: " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
//                    if ("-1".equals(res)) {
//                        //info = "请重新登录";
//                        MyToast("请重新登录");
//                        startActivity(new Intent(SettleAccountsActivity.this, LoginNewActivity.class));
//                        return;
//                    }
                    if ("1".equals(res)) {
                        JSONObject jsonObject1 = jsonObject.optJSONObject("info");
                        String order_no = jsonObject1.optString("order_no");
                        String msg = jsonObject1.optString("msg");
                        MyToast(msg);
                        String money = pay_money.getText().toString();
                        Intent intent = new Intent(SettleAccountsActivity.this, ChoosePayActivity.class);
                        intent.putExtra("order_no", order_no);
                        intent.putExtra("money", money);
                        startActivity(intent);
                        finish();
                    } else {
                        String info = jsonObject.optString("info");
                        MyToast(info);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                closeDialog();
                super.onError(ex, isOnCallback);
            }
        });
    }

    private void createOrder() {
        showDialog();
        Map<String, Object> map = new HashMap<>();
        StringBuilder builder = new StringBuilder("-");
        System.out.println("cartIds= " + beanList.size());
        for (int i = 0; i < beanList.size(); i++) {
            builder.append(beanList.get(i).getCart_id());
            builder.append("-");
        }
        map.put("other_type", payType);
        Log.e("----", payType + "");
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("cartIds", builder);
        map.put("addressId", addrId);
        map.put("receiptAddrId", receiptAddrId);
        map.put("invoiceType", invoiceType);
        map.put("invoiceTitle", invoiceTitle);
        map.put("company", company);
        map.put("remark", edit.getText().toString());
        map.put("if_receipt", isOpened);
        if (isOpened == 1) {
            map.put("invoiceId", invoiceId);
        }

        map.put("equipment", "android");
        map.put("version", "" + SystemUtils.getVersionName(SettleAccountsActivity.this));

        Map<String, Object> map2 = new HashMap<>();
        Set keys = map.keySet();
        if (keys != null) {
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Object key = iterator.next();
                Object value = map.get(key);
                Log.e("----" + key, "" + value + "\n");
                map2.put("" + key, value);
            }
        }
        XUtil.Post(Url.ORDER_JJMAKEORDER, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                closeDialog();
                super.onSuccess(result);
                Log.i(TAG, "onSuccess: invoiceTitle=  " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
//                    if ("-1".equals(res)) {
//                        //info = "请重新登录";
//                        MyToast("请重新登录");
//                        startActivity(new Intent(SettleAccountsActivity.this, LoginNewActivity.class));
//                        return;
//                    }
                    if ("1".equals(res)) {
                        JSONObject jsonObject1 = jsonObject.optJSONObject("info");
                        String order_no = jsonObject1.optString("order_no");
                        String msg = jsonObject1.optString("msg");
                        MyToast(msg);
                        String money = pay_money.getText().toString();
                        Intent intent = new Intent(SettleAccountsActivity.this, ChoosePayActivity.class);
                        intent.putExtra("order_no", order_no);
                        intent.putExtra("money", money);
                        startActivity(intent);
                        finish();
                    } else {
                        String info = jsonObject.optString("info");
                        MyToast(info);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                closeDialog();
                super.onError(ex, isOnCallback);
            }
        });
    }

    private void upOrder() {
        StringBuilder builder = new StringBuilder("-");
        System.out.println("cartIds= " + beanList.size());
        for (int i = 0; i < beanList.size(); i++) {
            builder.append(beanList.get(i).getCart_id());
            builder.append("-");
        }
        showDialog();
        Map<String, Object> map = new HashMap<>();
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("cartIds", builder);
        XUtil.Post(Url.ORDER_JJBUYPAGE, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                closeDialog();
                super.onSuccess(result);
                Log.i(TAG, "onSuccess: cartIds= " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String express_fee = jsonObject.optString("express_fee");
                    JSONArray jsonArray = jsonObject.optJSONArray("info");
//                    if ("-1".equals(res)) {
//                        //info = "请重新登录";
//                        MyToast("请重新登录");
//                        startActivity(new Intent(SettleAccountsActivity.this, LoginNewActivity.class));
//                        return;
//                    }
                    if ("1".equals(res)) {
                        if (jsonArray != null) {
                            list.clear();
                            for (int i = 0; i < jsonArray.length(); i++) {
                                FitmentBean bean = new FitmentBean();
                                Gson gson = new Gson();
                                bean = gson.fromJson(jsonArray.optString(i), FitmentBean.class);
                                list.add(bean);
                            }
                        }

                        //   freight_tv.setText("¥ " + express_fee);
//                        double allMoney = Double.parseDouble(allPrice) + Double.parseDouble(express_fee);
//                        pay_money.setText("" + allMoney);
                    }
                    adapter.notifyDataSetChanged();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                closeDialog();
                super.onError(ex, isOnCallback);
            }
        });
    }

    private int isOpened = 0;

    @Override
    public void toggleToOn(View view) {
        switchButton.setOpened(true);
        showOrHideInvoiceLayout(true);
        isOpened = 1;
    }

    @Override
    public void toggleToOff(View view) {
        switchButton.setOpened(false);
        showOrHideInvoiceLayout(false);
        isOpened = 0;
    }

    private String invoiceId = "";

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


        switch (requestCode) {

            //地址回调
            case CODE_ADDRESS:
                if (resultCode == RESULT_OK) {
                    if (null != data) {
                        AddressBean addressBean = (AddressBean) data.getSerializableExtra("addressBean");
                        include_address.setVisibility(View.VISIBLE);
                        include_noAddress.setVisibility(View.GONE);
                        String province = addressBean.getProvince();
                        String city = addressBean.getCity();
                        String district = addressBean.getDistrict();
                        String place = addressBean.getPlace();
                        String addr = province + city + district + place;
                        tv_name.setText(addressBean.getConsignee());
                        tv_phone.setText(addressBean.getTelephone());
                        tv_address.setText(addr);
                        addrId = addressBean.getAddress_id();

                        upfee(addrId);
                    }
                }
                break;

            //发票回调
            case CODE_INVOICE:
                if (resultCode == RESULT_OK) {
                    String name = data.getStringExtra("name");
                    invoiceId = data.getStringExtra("id");
                    invoice_tv.setText(name + "");
//                    if (null != data) {
//                        String getInvoiceResult = data.getStringExtra("InvoiceResult");
//                        receiptAddrId = data.getStringExtra("receiptAddrId");
//                        invoiceType = data.getStringExtra("invoiceType");
//                        invoiceTitle = data.getStringExtra("invoiceTitle");
//                        company = data.getStringExtra("company");
//                        receiptType = data.getStringExtra("receiptType");
//                        type = data.getStringExtra("type");
//                        invoice_tv.setText(getInvoiceResult);
//                        isInvoice = true;
//                    } else {
//                        isInvoice = false;
//                    }


                }
//                else if (resultCode == VALUE_TAX) {
//                    if (data != null) {
//                        String getInvoiceResult = data.getStringExtra("InvoiceResult");
//                        invoiceTitle1 = data.getStringExtra("invoiceTitle");
//                        taxpayerId = data.getStringExtra("taxpayerId");
//                        bank = data.getStringExtra("bank");
//                        bankAccount = data.getStringExtra("bankAccount");
//                        address = data.getStringExtra("address");
//                        phone = data.getStringExtra("phone");
//                        type = data.getStringExtra("type1");
//                        invoice_tv.setText(getInvoiceResult);
//                    }
//                }
                Log.e("-----", "type" + type);
                break;

            default:
                break;
        }


    }

    private static final String TAG = "SettleAccountsActivity";
    private double moneyInfo = 0;
    private boolean isTure;

    private void upfee(final String addrId) {
        showDialog();
        Map<String, Object> map = new HashMap<>();

        map.put("addressId", addrId);
        map.put("weight", weight + "");
        XUtil.Post(Url.ORDER_CHANGEEXPRESSFEE, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                closeDialog();
                super.onSuccess(result);
                Log.i(TAG, addrId + "onSuccess: weight= " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String info = jsonObject.optString("info");

                    double allMoney = 0;
                    if ("1".equals(res)) {
                        moneyInfo = Double.parseDouble(info);
                        switch (payType) {
                            case 0:
                                freight_tv.setText("¥" + moneyInfo);
                                allMoney = Double.parseDouble(allPrice) + moneyInfo;
                                break;
                            case 1:
                                allMoney = Double.parseDouble(allPrice);
                                freight_tv.setText("到付");
                                break;
                            case 2:
                                allMoney = Double.parseDouble(allPrice);
                                freight_tv.setText("自提");
                                break;
                        }
                        pay_money.setText("" + allMoney);
                    } else {
                        MyToast(info);
                        isTure = false;
                        freight_tv.setText("¥0.0");
                        pay_money.setText("" + allMoney);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                closeDialog();
                super.onError(ex, isOnCallback);
            }
        });
    }
}
